﻿using System;
using IterationLife.Domains.Sports.Enums;
using IterationLife.Domains.Sports.Models;

namespace IterationLife.Domains.Sports.Dtos.MTSports
{
    public class MTUserInfo
    {
        public int uid { get; set; }
        public string name { get; set; }
        public int? personId { get; set; }
        public int? person_id { get; set; }

        public string nickName { get; set; }

        public string userName { get; set; }

        public string mobile { get; set; }

        public string avatarCenter { get; set; }

        public int? sex { get; set; }

        public string idCard { get; set; }

        public DateTime? birthday { get; set; }

        public string token { get; set; }

        public decimal height { get; set; }

        public decimal weight { get; set; }
    }

    public static class MTUserInfoExtension
    {
        public static SportUser ToSportUser(this MTUserInfo userInfo)
        {
            var result = new SportUser(Guid.NewGuid());
            SetEntityValue(result, userInfo);
            return result;
        }

        public static SportAthlete ToAthlete(this MTUserInfo userInfo, Guid id)
        {
            var result = new SportAthlete(id);
            SetEntityValue(result, userInfo);
            return result;
        }

        public static void SetEntityValue(SportUser sportUser, MTUserInfo userInfo)
        {
            sportUser.PartnerUserId = userInfo.uid.ToString();
            sportUser.EquipmentType = EquipmentType.MT;
            sportUser.Token = userInfo.token;
            sportUser.Mobile = userInfo.mobile;
            sportUser.Photo = userInfo.avatarCenter;
        }

        public static void SetEntityValue(SportAthlete athlete, MTUserInfo userInfo)
        {
            athlete.PartnerAthleteId = userInfo.person_id.ToString();
            athlete.Name = userInfo.name;
            athlete.IdCard = userInfo.idCard;
            athlete.Sex = userInfo.sex.Value;
            athlete.Birthday = userInfo.birthday;
            athlete.Weight = userInfo.weight;
            athlete.Stature = userInfo.height;
        }
    }
}
